


from analyse.kline_handler.enum import RiseAndFallType, ShapeType
from analyse.trend_handler.volume_handler import TrendVolumeHandler
import numpy as np


class KlineVolumeHandler(TrendVolumeHandler):
    def analyse(self,props):
        parent=props["parent"]
        kline=props["kline"]
        klineType=props["klineType"]
        index=props["index"]
        klines=props["klines"]
        init_trend=props["init_trend"]


        # 如果一字涨停或跌停，跳过
        if klineType["shape_type"]==ShapeType.一字.value and (klineType["rise_and_fall_type"]==RiseAndFallType.上涨.value or klineType["rise_and_fall_type"]==RiseAndFallType.下跌.value):
            return


        day_5_start_index=max(index-6,0)
        prev_index=index-1
        kline_range=klines[day_5_start_index:index]
        day_5_avg_volume=float(np.mean([kline["volume"] for kline in kline_range]))
        prev_volume=klines[prev_index]["volume"]
        volume=kline["volume"]

        if (volume/day_5_avg_volume)>=2 and (volume/prev_volume)>=2:
            parent.push_trend()
            init_trend()
            parent.push_trend()
            
        

        

